package cn.webrx.mapper;

import cn.webrx.pojo.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

public interface RoleMapper {
    @Select("select * from w_role where name = #{name}")
    @Results(id = "rolesmap", value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "members", column = "id", many = @Many(select = "selrole", fetchType = FetchType.LAZY))
    })
    public Role queryByName(String name);

    @Select("select m.id,m.account,m.password from w_memberrole mr join w_member m on mr.role_id = ${id} and m.id = mr.member_id")
    public List<Map<String, Object>> selrole(int id);

    @Select("select * from w_role")
    @ResultMap("rolesmap")
    public List<Role> queryAll();
}
